# -*- coding = utf-8 -*-
# @Time    : 2025/3/31 下午5:08
# @Author  : yqk
# @File    : selenium豆瓣.py
# @Software: PyCharm
import time

# 登录豆瓣
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

service = Service(r'D:\python-code\chromedriver-win64\chromedriver.exe')

opt = Options()
opt.add_argument('--disable-blink-features=AutomationControlled')
opt.page_load_strategy = 'normal' # 默认是normal，normal：等待页面完全加载完成，eager：等待页面基本加载完成，interactive：等待页面基本加载完成，但是不加载图片，css，js等资源，这个性能最好，但是页面加载速度会慢一点
browser = webdriver.Chrome(service=service, options=opt)
browser.implicitly_wait(5)
url = 'https://www.douban.com/'
browser.get(url)
time.sleep(3)
iframe = browser.find_element(By.XPATH, '//*[@id="anony-reg-new"]/div/div[1]/iframe')
browser.switch_to.frame(iframe)
browser.find_element(By.XPATH, '/html/body/div[1]/div[1]/ul[1]/li[2]').click()
browser.find_element(By.XPATH, '//*[@id="username"]').send_keys('14780197596')
time.sleep(1)
browser.find_element(By.XPATH, '//*[@id="password"]').send_keys('yqk123456')
time.sleep(1)
browser.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[1]/div[5]/a').click()
browser.switch_to.default_content()
time.sleep(3)
browser.close()


